//
//  CHSTableViewCell.m
//  CAIPluginsManager_Example
//
//  Created by simon on 2022/1/7.
//  Copyright © 2022 海参. All rights reserved.
//

#import "CHSTableViewCell.h"

@implementation CHSTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        if (@available(iOS 14.0, *)) {
            self.backgroundConfiguration = [UIBackgroundConfiguration clearConfiguration];
        } else {
            // 默认
            self.backgroundColor = [UIColor whiteColor];
        }
        //默认透明
        self.contentView.backgroundColor = [UIColor clearColor];
        [self setUI];
    }
    return self;
}
- (void)setUI{
    
    [self.contentView addSubview:self.menuIconCollectionView];
    [self.menuIconCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.contentView);
    }];
}

- (CAIMenuIconPluginKit *)menuIconCollectionView
{
    if (!_menuIconCollectionView) {
        CAIMenuIconPluginKit *view = [[CAIMenuIconPluginKit alloc] init];
        view.columnsCount = 5;
//        view.minimumInteritemSpacing = LCDScale_iPhone6(12);
//        view.sectionInset = UIEdgeInsetsMake(
//                                             LCDScale_iPhone6(12)-[MenuItemCell getImageViewToSupViewDefaultTop],
//                                             LCDScale_iPhone6(12),
//                                             0,
//                                             LCDScale_iPhone6(12));
//        view.minimumLineSpacing = LCDScale_iPhone6(10)-[MenuItemCell getImageViewToSupViewDefaultTop];
//        view.titleLabToImageViewSpace = LCDScale_iPhone6(5);
//        view.iconSquareSideLength = LCDScale_iPhone6(50);
        CGSize size = [view getItemMiniSafeSizeWithTotalWidth:SCREEN_WIDTH-LCDScale_iPhone6(12*2) columnsCount:view.columnsCount sectionInset:view.sectionInset minimumInteritemSpacing:view.minimumInteritemSpacing hasBadge:NO iconSquareSideLength:view.iconSquareSideLength titleLabToImageViewSpace:view.titleLabToImageViewSpace];
        view.itemSize = size;
//        view.placeholderImage = [UIImage imageNamed:@"placeholder_loading90"];
//        view.titleLableFont = [UIFont systemFontOfSize:LCDScale_iPhone6(12)];
//        view.titleLabelTextColor = [UIColor caiColorWithHexString:@"#333333"];
        view.backgroundColor = [UIColor orangeColor];
        _menuIconCollectionView = view;
    }
    return _menuIconCollectionView;
}

- (void)setData:(id)data
{
    NSArray *dataArray = (NSArray *)data;
 
    [self.menuIconCollectionView setData:dataArray];

//    [data enumerateObjectsUsingBlock:^(MessageModelSub *  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
//
//       MenuItemModel *model = [[MenuItemModel alloc] init];
//       model.icon = obj.typeIcon;
//       model.title = obj.typeName;
//       if (obj.num>0) {
//           model.sideMarkType = SideMarkTypeNumber;
//       }else{
//           model.sideMarkType = SideMarkTypeNone;
//       }
//       model.sideMarkValue = [NSString stringWithFormat:@"%@",@(obj.num)];
//       [mArray addObject:model];
//    }];
//    [self.menuIconCollectionView setData:mArray];
}

- (CGFloat)getCellHeightWithContentIndexPath:(NSIndexPath *)indexPath data:(id)data
{
    return [self.menuIconCollectionView getCellHeightWithContentData:data];
}

@end
